url = '/:slug|[a-z0-9\-]+-p-\d+.html$'
description = '产品内容页模板'
layout = 'default-x'
==
use Jason\Ccshop\Components\Catalog;
use Jason\Ccshop\Models\Promotion;
function onStart(){
	$slugArr = explode('-', str_replace('.html', '', $this->param('slug')));
	$id = array_pop($slugArr);
	$condition = ['id'=>$id];
	$product = App::make('Jason\Ccshop\Controllers\Products')->getProduct($condition);
	if ($product) {
		//$featureImageCount = count($product['feature_image']);
		//if($featureImageCount < 9){
		//	preg_match_all('/<\s*img\s+[^>]*?src\s*=\s*(\'|\")(.*?)\\1[^>]*?\/?\s*>/i',$product['content'], $match);
		//	$contentImages = isset($match[2]) ? $match[2] : [];
		//	if(!empty($contentImages)){
		//		foreach($contentImages as $contentImage){
		//			if(stripos($contentImage,'.png')===false){
		//				$product['feature_image'][] = ['title' => '', 'path' => $contentImage];
		//			}
		//			if(count($product['feature_image'])==9){
		//				break;
		//			}
		//		}
		//	}
		//}
		$this['product'] = $product;
	} else {
		return redirect('/404');
	}
     
	 //促销产品
	$this['promotionLabel'] = '';
	//现在促销的
    $promotion = Promotion::where('name', 'christmas_now')->first();
    $now = time();
    if( $promotion && strtotime($promotion->from_date) < $now && strtotime($promotion->to_date) > $now){
        $promotions = (new Catalog)->getProductsByPromotionName('christmas_now'); 
        foreach($promotions as $promo){
           if($product['id']==$promo['id']){
             $this['promotionLabel'] = 'proNow';
             break;
          }
        }
    }

   //下一期促销的
    //if(!$this['promotionLabel']){
    //   $promotion = Promotion::where('name', 'christmas_next')->first();
    //   if($promotion && strtotime($promotion->from_date) > $now){
    //    $promotions = (new Catalog)->getProductsByPromotionName('christmas_next'); 
    //    foreach($promotions as $promo){
    //       if($product['id']==$promo['id']){
    //         $this['promotionLabel'] = 'proNext';
    //         break;
    //      }
    //    }
   // }     
  // }

    //dd($promotions);
    //dd($this['promotionLabel']);
    if($this['promotionLabel']){
     $this['from_date'] = strtotime($promotion->from_date);
     $this['to_date']  = strtotime($promotion->to_date);
     $this['now_date']  = $now;
    }
}
==
{% set reviews = catalog.getReviews(product.id) %}
{% put page_title %} {{product.name}} -{{ domain|slice(7) }}{% endput %}
{% put meta_keywords %} {{ product.meta_keywords }}{% endput %}
{% put meta_description %}{{ product.meta_description }} {% endput %}
{# GA代码4_动态赋值 #}
{% put fb_standard_event %}
    fbq('track', 'ViewContent', {
        content_type:'product',
        content_ids:"{{ product.id }}",
        content_name: "{{ product.name }}",
        value: {{ product.price|ratePrice }},
        currency: 'JPY'
    });
{% endput %}
<div class="product_content">
	<!-- breadcrumbs -->
	{% partial 'common/breadCrumb' product=product categories=product.categories %}
	<!-- breadcrumbs end -->
	<div class="productCont">
		<div class="container">
		<form action="#" method="POST" id="product_addtocart_form">
			<div class="productItemData">
				<div class="fl">
					<ul id="example3">
						{% for key, img in product.feature_image %}
						<li {% if loop.index == 1 %} class="active"{% endif %}>
							<img class="etalage_thumb_image" src="{{ img.path }}" />
							<img class="etalage_source_image" src="{{ img.path }}" />
						</li>
						{% endfor %}
					</ul>
				</div>
				
				<div id="promotionNow" style="display: none">
                {% if promotionLabel %}
                <h4 class="starttime">{{ from_date |date("Y/m/d H:i:s")  }}</h4>
                <h4 class="endtime">{{ to_date |date("Y/m/d H:i:s")  }}</h4>
                <h4 class="nowtime">{{ now_date |date("Y/m/d H:i:s")  }}</h4>
                {% endif %}  
                </div>

				<div class="fr">

					<p class="mb10"><img src="{{ 'assets/img/new.png'|theme }}" alt="" width="36" height="17"></p>
	
					<h2 class="productHead mb15">{{ product.name }}</h2>
					<p class="productPrice mb15"><span>{{ product.price|formatPrice }}</span>（税込）
						{% if promotionLabel=='proNow' %}
						    <span style="float: right;"><span style="font-size: 12px;">残り時間：</span>
					        <span id="date-1" style="font-size: 12px;"></span></span>     
					    {% endif %}
					<br>
						<s>{{ product.list_price|formatPrice }}</s>（税込）&nbsp; {{ product.discount}} OFF  
					<br>
						ポイント:	 {{ getProductPoint(product.id) }}
					</p>
				<div class="product_id">
            			<h2>商品番号：<span>{{ product.id }}</span></h2>
            			<div class="availability {% if product.status == 'instock' %}in-stock{% else %}out-of-stock{% endif %}">
							<span>{{ ('jason.ccshop::lang.product.status.' ~ product.status)|trans }}</span></div>
            			<span class="reviewStar size2 star{{ reviews.rating_stat.avg | round }}"></span>
           				 <a href="#reviews" class="reviewsShow">レビュー / <b>{{ reviews.total }}</b> 件</a>
         		 </div>
          	
					<div class="option-element">
						{% for option in product.options %}
							
							<div class="changeBox mb15">
					            <h2> {{option.name}} :   <span class="changeText"></span></h2>
				            	<div class="color_change">
				            		{% if option.values is iterable %}
				            			{% for val in option.values %}
											<label class="radio-inline">
						                		<input type="radio" name="ProductOption[{{ option.id }}]" {% if loop.index ==  1 %}checked{% endif %} class="radio" value="{{val.id}}">
						                		{% if val.thumb.path %}
							                        <span>
							                       		<img src="{{val.thumb.path}}" alt="{{ val.name }}" title="{{ val.name }}"  width="62" height="72">
							                       	</span>
						                       	{% else %}
						                       		<span> <b class="text">{{ val.name }}</b> </span>
						                       	{% endif %}
						                    </label>
				            			{% endfor %}
				            		{% endif %}				                    
				                    
				                </div>
							</div>	

						{% endfor %}							
						
						<div class="changeNum">
							<h2> 個数:  <input type="text" class="changeNumIpt" value="1" name="qty"></h2>
						</div>
						
						<div class="add-cart-box" data-request-data="product:'{{ product.id }}'">
							{% if product.status == 'instock' %}
							<button class="btn-add-mybag blueBtn1" id="onAddToCart" data-request="onAddToCart" data-request-redirect="{{ ''|page }}" data-request-update="'common/shopping-cart':'.min_cart'">
								ショッピングバッグに入れる
							</button>
							{% else %}
								<button class="btn-add-mybag blueBtn1" disabled style="background: #ccc;">在庫切れ</button>
							{% endif %}	
							
						</div>
						<button class="btn-add-favorite bd_none" data-request="onAddToWishlist" data-request-data="key: {{ product.id }}">
								お気に入りに追加する
								<span class="wishNum">{{  product.custom_fields['wish_total']}}</span>
							</button>
						
					</div>
				</div>				
			</div>
		</form>	
			<br style="clear: both;">
			<div>
				
				 <ul class="text_switch" id="reviews">
        			<li class="active">商品詳細</li>
        			<li>レビュー / <b>{{ reviews.total }}</b> 件</li>
      			</ul>
				<div class="review_content">
					<div class="contentText">
        				
							<div class="text_content">
								{{ product.content|raw }}
							</div>
				        	<div class="text_content">
				          				{{ form_ajax('onPushReview') }}
				         				<input type="hidden" name="product" value="{{ product.id }}">
				          				<input type="hidden" name="name" value="{{ user.name }}">
				          				<input type="hidden" name="title" value="レビュー">
				          				<label class="label-wide" for="review_field">レビュー <em>*</em></label>
				          				<textarea class="required-entry" rows="3" cols="5" id="review_field" name="content" style="height:100px;"></textarea>          
				         		<div class="review_btm">
				           				 <input type="radio" class="radio" value="1" id="Quality_1" name="rating">1*
				           				 <input type="radio" class="radio" value="2" id="Quality_2" name="rating">2*
				            			<input type="radio" class="radio" value="3" id="Quality_3" name="rating">3*
				           				 <input type="radio" class="radio" value="4" id="Quality_4" name="rating">4*
				            			<input type="radio" class="radio" value="5" id="Quality_5" name="rating">5*
				            			{% if user.email%}
				            			<button class="button submit" title="Submit Review" type="submit" ><span>提出する</span></button>
				           				 {% else %}
				            				<a href="{{ 'account/login'|page }}">登録する後で</a>
				            			<button class="button submit" disabled style="background:#eee;border:1px #ddd solid;color:#000;float: right;height: 35px;" ><span>提出する</span></button>
				            			{% endif %}
				         		</div>
				          					{{ form_close() }}
				         		 <div class="review_cont">
				           				 <label class="label-wide">お客様のレビュー</label>
				           				<div class="reviewArea_header">
				             				<div>
				                  				<b>総合評価</b>
				                  				<span class="reviewStar size2 star{{ reviews.rating_stat.avg | round }}"></span>
				             				 </div>
				              				<div class="cnt">
				                  				<b>({{ reviews.total }})</b>レビュー
				              				</div>
				           				 </div>
				           						 {% for key, review in reviews %}
				            			<div class="review_text">
				              				<p class="text_color">{{ getReviewsName(review.name) }} <b>{{ review.created_at | date("Y/m/d") }}</b></p>
				              				<p><span class="reviewStar size1 star{{ review.rating | round }}"></span></p>
				              				<p>{{ review.content }}</p>
				            			</div>
				            				{% endfor %}
				            			<div class="actions" style="margin-top:10px;">
				              				<div class="pager">
				                				<div class="pages">
				                  					{{ reviews.fragment('reviews').render()|raw }}
				                				</div>
				              				</div>
				            		</div>
				          		</div>
				        	</div>
				      </div>
				</div>
			</div>
			{% partial 'catalog/product-recommend' pid=product.id code='product-related' %}
		</div>
	</div>
</div>
{% put scripts %}
<script type="text/javascript">
    $(".review_content").find("table").each(function(i,item){
        $(item).removeAttr("style")
    });

    $(function(){
    // time-sale-ul
    // $(".time-sale-ul li").click(function () {
    //     var index = $(this).index();
    //     $(this).addClass("active").siblings().removeClass("active");
    //     $(".time-sale-box .time-sale-cont").eq(index).show().siblings().hide();
    // });
    // time-sale
	// $(".starttime").hide();
 //    $(".endtime").hide();
 //    $(".nowtime").hide();
    // $(".time-sale-box .time-sale-cont:eq(0) .time-sale-item").each(function(index){
    //     initmake(this)
    // });
    $("#promotionNow").each(function(index){
         initmakeNow(this)
     });

    // $("#promotionNext").each(function(index){
    //     initmakeNext(this)
    //  });
    function initmakeNow(that){ 
        var starttime = $(that).find(".starttime").text();        
        var endtime = $(that).find(".endtime").text();
        var nowtime = $(that).find(".nowtime").text();
        startdjs();
        function startdjs(){
            starttime = new Date(starttime).getTime();
            nowtime = new Date(nowtime).getTime();
            var chastart = starttime-nowtime;
            var startinterval = setInterval(function(){
                chastart=chastart-1000;
                var d = Math.floor(chastart/1000/60/60/24);         
                var h = Math.floor(chastart/1000/60/60%24);
                var i = Math.floor(chastart/1000/60%60);
                var s = Math.floor(chastart/1000%60);  
                if(d<=0&&h<=0&&i<=0&&s<=0){
                    clearInterval(startinterval);
                    enddjs();
                }else{
                    $("#date-1").html(d+":"+h+":"+i+":"+s);
                }
            }, 1000);       
        }
        function enddjs(){
            endtime = new Date(endtime).getTime();
            nowtime = new Date(nowtime).getTime();
            var chaend = endtime-nowtime;            
            var endinterval = setInterval(function(){
                chaend=chaend-1000;
                var d = Math.floor(chaend/1000/60/60/24);           
                var h = Math.floor(chaend/1000/60/60%24);
                var i = Math.floor(chaend/1000/60%60);
                var s = Math.floor(chaend/1000%60);
                if(d<=0&&h<=0&&i<=0&&s<=0){
                    clearInterval(endinterval)
                }else{
                    $("#date-1").html(d+":"+h+":"+i+":"+s);
                }
            }, 1000);       
        }
    }

        function initmakeNext(that){ 
        var starttime = $(that).find(".starttime").text();        
        var endtime = $(that).find(".endtime").text();
        var nowtime = $(that).find(".nowtime").text();
        startdjs();
        function startdjs(){
            starttime = new Date(starttime).getTime();
            nowtime = new Date(nowtime).getTime();
            var chastart = starttime-nowtime;
            var startinterval = setInterval(function(){
                chastart=chastart-1000;
                var d = Math.floor(chastart/1000/60/60/24);         
                var h = Math.floor(chastart/1000/60/60%24);
                var i = Math.floor(chastart/1000/60%60);
                var s = Math.floor(chastart/1000%60);  
                if(d<=0&&h<=0&&i<=0&&s<=0){
                    clearInterval(startinterval);
                    enddjs();
                }else{
                    $("#date-2").html(d+":"+h+":"+i+":"+s);
                }
            }, 1000);       
        }
        function enddjs(){
            endtime = new Date(endtime).getTime();
            nowtime = new Date(nowtime).getTime();
            var chaend = endtime-nowtime;            
            var endinterval = setInterval(function(){
                chaend=chaend-1000;
                var d = Math.floor(chaend/1000/60/60/24);           
                var h = Math.floor(chaend/1000/60/60%24);
                var i = Math.floor(chaend/1000/60%60);
                var s = Math.floor(chaend/1000%60);
                if(d<=0&&h<=0&&i<=0&&s<=0){
                    clearInterval(endinterval)
                }else{
                    $("#date-2").html(d+":"+h+":"+i+":"+s);
                }
            }, 1000);       
        }
    }
});
</script>
{% endput %}
<script type="text/javascript">
var google_tag_params = {
	ecomm_prodid: "{{product.id}}",
	ecomm_pagetype: "product",
	ecomm_totalvalue: {{product.price|ratePrice }}
};
</script>




